package net.daum.webtoon.android.dto;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import net.daum.webtoon.android.MainActivity;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

public class DTO_WebToon extends JSonDataObjectBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 101L;

	public String lastTouch;
	public String viewerType;
	public String title;

	////
	public String startDate;
	public String averageScore;
	public DTO_Cartoon cartoon;
	public String diff;

	public String englishTitle;
	public String seriesYn;
	public String tag;
	public String score;
	public String webtoonWeeks;

	public String seriesWebtoons;
	public String articleId;
	public String payYn;
	public String commentUseYn;
	public String id;

	public String event;
	public String webtoonComment;
	public String titleHtml;
	public String hasPadtoon;
	public String viewerEvent;
	public String webtoonType;
	public String finishYn;
	public String weekTerm;
	public String nickname;
	public String isNew;
	public String padtoonYn;
	public String webtoonGroupId;
	public String finishDate;
	public String webtoonEpisodes;
	public String url;
	public String price;
	public String serviceStatus;

	public String webtoonServices;
	public String latestWebtoonEpisode;
	public String dateCreated;
	public String ageGrade;
	public String ranking;
	public String mobileYn;
	public String media;
	public String padYn;
	public String introduction;

	public DTO_PictureImage titleImage;
	public DTO_PictureImage titleImage2;
	public DTO_PictureImage thumbnailImage;
	public DTO_PictureImage thumbnailImage2;
	public DTO_PictureImage padThumbnailImage;
	public DTO_PictureImage artistCommentImage;
	public DTO_PictureImage homeThumbnailImage;

//	public DTO_PictureImage padThumbnailImage;
//	public DTO_PictureImage artistCommentImage;
//	public DTO_PictureImage thumbnailImage;
//	public DTO_PictureImage thumbnailImage2;

/////
	public static String TAG = DTO_WebToon.class.getSimpleName();

	public DTO_WebToon() {
//		updateDay = new HashMap<String, Boolean>();
//		updateDay.put("MON", false);
//		updateDay.put("TUE", false);
//		updateDay.put("WED", false);
//		updateDay.put("THU", false);
//		updateDay.put("FRI", false);
//		updateDay.put("SAT", false);
//		updateDay.put("SUN", false);
	}

	public DTO_WebToon(JSONObject aJsonObject) {
		Iterator<Object> iterator = aJsonObject.keys();

		while (iterator.hasNext()) {
			Object obj = iterator.next();
			if (obj.toString().equalsIgnoreCase("cartoon")) {
				try {
					this.cartoon = new DTO_Cartoon(aJsonObject.getJSONObject("cartoon"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("titleImage")) {
				try {
					this.titleImage = new DTO_PictureImage(aJsonObject.getJSONObject("titleImage"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("titleImage2")) {
				try {

					this.titleImage2 = new DTO_PictureImage(aJsonObject.getJSONObject("titleImage2"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("thumbnailImage")) {
				try {
					this.thumbnailImage = new DTO_PictureImage(aJsonObject.getJSONObject("thumbnailImage"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("thumbnailImage2")) {
				try {
					this.thumbnailImage2 = new DTO_PictureImage(aJsonObject.getJSONObject("thumbnailImage2"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("padThumbnailImage")) {
				try {
					this.padThumbnailImage = new DTO_PictureImage(aJsonObject.getJSONObject("padThumbnailImage"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("artistCommentImage")) {
				try {
					this.artistCommentImage = new DTO_PictureImage(aJsonObject.getJSONObject("artistCommentImage"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else if (obj.toString().equalsIgnoreCase("homeThumbnailImage")) {
				try {
					this.homeThumbnailImage = new DTO_PictureImage(aJsonObject.getJSONObject("homeThumbnailImage"));
				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}
			} else {
				setMemberFiled(this, aJsonObject, obj.toString());
			}
		}
		if (this.lastTouch == null || this.lastTouch.length() < 1) {
			this.lastTouch = String.valueOf(System.currentTimeMillis());
		}
		printMembers();
		insertObjToDB();
	}

	public void setRead(Context aCtx) {
		Map<String, Object> lMap = new HashMap<String, Object>();
		lMap.put("lastTouch", this.lastTouch);
		upadeat(aCtx, lMap);
	}
}
